package com.lc.yygh.order.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lc.YYGH.common.result.Result;
import com.lc.YYGH.common.utils.AuthContextHolder;
import com.lc.YYGH.enums.OrderStatusEnum;
import com.lc.YYGH.vo.order.OrderCountQueryVo;
import com.lc.YYGH.vo.order.OrderInfo;
import com.lc.YYGH.vo.order.OrderQueryVo;
import com.lc.yygh.order.service.OrderInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags="订单接口")
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoApiController {
    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation(value="创建订单")
    @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
    public Result submitOrder(
        @ApiParam(name="scheduleId",value="排班id",required = true)
        @PathVariable String scheduleId,
        @ApiParam(name="patientId",value="就诊人id",required=true)
        @PathVariable Long patientId)
    {
        return Result.success(orderInfoService.saveOrder(scheduleId,patientId));

    }

    @ApiOperation(value="获取订单统计数据")
    @PostMapping("inner/getCountMap")
    public Map<String,Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo)
    {
        return orderInfoService.getOrderCountMap(orderCountQueryVo);
    }
    //根据订单id查询订单详情
    @GetMapping("auth/getOrders/{orderId}")
    public Result getOrders(@PathVariable Long orderId)
    {
        OrderInfo orderInfo=orderInfoService.getById(orderId);
        return Result.success(orderInfo);
    }

    @GetMapping("auth/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       OrderQueryVo orderQueryVo, HttpServletRequest request
                       ){
        orderQueryVo.setUserId(AuthContextHolder.getUserId(request));
        Page<OrderInfo> pageParam=new Page<>(page,limit);
        IPage<OrderInfo> pageModel=orderInfoService.selectPage(pageParam,orderQueryVo);
        return Result.success(pageModel);

    }
    @ApiOperation(value="获取所有订单状态")
    @GetMapping("auth/getStatusList")
    public Result getStatusList()
    {
        return Result.success(OrderStatusEnum.getStatusList());
    }

}
